home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareworld 7
/
Shareworld 7 (Disk 2 of 2).adf
/
SW7MachineLang.Examples
/
MLExampleSW7.asm
< prev
next >
Wrap
Assembly Source File
|
1978-02-07
|
3KB
|
110 lines
;An example program to show the use of the BTST, the ASL, the AND,
;the LSL, the LSR, and the OR commands.
;Published with ShareWorld 7 - by Matthew Goode 27/9/96
;Try to work out how everything works, explanations will be given
;next time. An important skill to develope is being able to read
;other peoples code, and understand it.
;Note:Uses non-op friendly code, which should not be practised in real
;programs (IE:DON'T use memory address directly!). Also the loops used
;here are bad because they suck up processor time (and don't run at
;the same speed on all Amigas).
; -------------------------------------------------------------------
; ---------------------------Constants-------------------------------
backgroundColourLoc = $dff180
buttonInfoLoc = $bfe001
; -------------------------------------------------------------------
; -------------------------Main program------------------------------
Start
Move.l #100000,d0
Move.l #4,d1
Bsr MultiplyLong
Cmp.l #400000,d2
Bne noFlash ;Just checking that the routine works
Bsr StrobeRedYellow
;Bsr StretchedStrobeBlue ;Try this one later
noFlash
move.l #0,d0 ;Set no error condition code
Rts
; -------------------------------------------------------------------
; -------------------------Sub-routines------------------------------
MultiplyLong
; A simple routine to take two long values (in d0,d1) and
;return (in d2) the product of these two values.
;Altered: d1,d2,d3
Move.w #0,d3 ;D3 will become a 'bit counter'
Move.l #0,d2
loopML1
Btst d3,d0
beq NoSet ;Is bit 'd2' set?
Set
Add.l d1,d2
NoSet
Asl.l #1,d1 ;Multiply d1 by 2
Add.w #1,d3
Cmp.w #32,d3 ;Have we checked every bit?
Bne loopML1
Rts
; -------------------------------------------------------------------
StrobeRedYellow
;Will strobe the background colour through various shades of green
;until the mouse button is pushed.
;An example of the And command, and shifting.
;Altered:d0,d1
Move.w #0,d0 ;Our counter
loopSRY1
Add.w #1,d0
And.w #%1111,d0 ;Increment our counter, keeping it within the
;range of 0-15
Move.w d0,d1 ;Move d0 to workspace
Lsl.w #4,d1 ;Shift value to 'green' area of an RGB value
;(bits 0-3 are blue, 4-7 are green, and 8-11 are red)
Or.w #%111100000000,d1 ;Set Red component to full
Move.w d1,backgroundColourLoc ;Set Background colour
Btst #6,buttonInfoLoc ;Here we are testing the bit in memory that tells
;us information about the state of the left mouse
;button.
;If the bit is set it means the button is NOT pushed
Bne loopSRY1
Rts
; -------------------------------------------------------------------
StretchedStrobeBlue
;Will strobe the background colour through various shades of blue
;until the mouse button is pushed.
;The pattern is streched out more that with StrobeGreen, try and
;see why? (Again explained next time).
;An example of the And command, and shifting.
;Altered:d0,d1
Move.w #0,d0 ;Our counter
loopSSB1
Add.w #1,d0 ;Increment our counter.
Move.w d0,d1 ;Move d0 to workspace
Lsr.w #8,d1 ;Shift to make d0 much smaller (will only change every
;256 times this loop execute)
And.w #%1111,d1 ;Increment our counter
;(bits 0-3 are blue, 4-7 are green, and 8-11 are red)
Move.w d1,backgroundColourLoc ;Set Background colour
Btst #6,buttonInfoLoc ;Here we are testing the bit in memory that tells
;us information about the state of the left mouse
;button.
Bne loopSSB1
Rts